<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 600px;
        height: 300px;
        margin: 100px auto;
        text-align: center;
      }
      p {
        font-size: 40px;
        font-weight: 700;
      }
      .time {
        /* float: left; */
        color: orange;
        font-size: 42px;
        /* text-align: center; */
        margin-left: 50px;
      }
      .time .days {
        float: left;
        margin-top: 40px;
      }
      .time ul {
        float: left;
        padding: 0;
      }
      .time ul li {
        float: left;
        list-style: none;
        height: 50px;
        width: 100px;
        font-weight: 700;
        color: #fff;
        margin-left: 20px;
        line-height: 50px;
        background-color: orange;
        border-radius: 5px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <p>距离光棍节，还有</p>

      <div class="time">
        <span class="days"></span>
        <ul class="shijian">
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </div>
    </div>
    <script>
      getDay();
      setInterval(getDay, 1000);
      function getDay() {
        var days = document.querySelector(".days");
        var shijian = document.querySelector(".shijian");
        function getTime(time) {
          var nowtime = +new Date();
          var inputtime = +new Date(time);
          var times = (inputtime - nowtime) / 1000;
          var day = parseInt(times / 60 / 60 / 24);
          day = day > 10 ? day : "0" + day;
          days.innerHTML = `${day}天`;
          var h = parseInt((times / 60 / 60) % 24);
          h = h > 10 ? h : "0" + h;
          shijian.children[0].innerHTML = `${h}时`;
          var m = parseInt((times / 60) % 60);
          m = m > 10 ? m : "0" + m;
          shijian.children[1].innerHTML = `${m}分`;
          var s = parseInt(times % 60);
          s = s > 10 ? s : "0" + s;
          shijian.children[2].innerHTML = `${s}秒`;
          //   return `${day}天${h}小时${m}分钟${s}秒钟`;
        }
        console.log(getTime("2022-11-11 0:0:0"));
      }
    </script>
  </body>
</html>
